package com.yjt.fresh.widget;

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * Created by UPC on 2018/6/10.
 */

public class SpaceItemDecorationHorizontal extends RecyclerView.ItemDecoration {
    int mSpace;
    int mSpaceCount;

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);
        if (mSpaceCount == 0) {
            outRect.left = mSpace;
            if (parent.getChildAdapterPosition(view) == 0) {
                outRect.left = 0;
            }
        } else {
            outRect.right = 0;
            if (parent.getChildAdapterPosition(view) % mSpaceCount == 0) {
                outRect.left = 0;
            }else {
                outRect.left = mSpace;
            }
        }

    }

    public SpaceItemDecorationHorizontal(int space) {
        mSpace = space;
    }

    public SpaceItemDecorationHorizontal(int space, int spaceCount) {
        mSpace = space;
        mSpaceCount = spaceCount;
    }
}